package controler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import view.Ligne_view;
import model.Dice;
import main.Game;

public class DiceListener implements ActionListener{
	Dice dices = new Dice();
	int total;
	Game game;
	Ligne_view lv;
	//constructor with Game as argument.
	public DiceListener(Game g, Ligne_view lv){
		this.game=g;
		this.lv=lv;
	}

	//What to do when dices are throw
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand()=="Throw Dices"){
			total = dices.throw_dice();

			//if player not perform a double, he can't replay but he can finish his turn
			if(!dices.isDouble()){
				lv.throw_dice.setEnabled(false);
				lv.finish_turn.setEnabled(true);
				game.movePlayer(total);
			}

			//if player perform a double, he must replay and can't finish his turn.
			else{
				if(game.canReplay(dices.isDouble())){
					lv.throw_dice.setEnabled(true);
					lv.finish_turn.setEnabled(false);
					game.movePlayer(total);

					lv.logText.setText(lv.logText.getText()+"\nYou have made a double ! Replay !");
				}
			}
		}
	}
}
